{% extends "base.html" %}

{% block content %}
<div class="container mt-4">
    <h2>产品分析结果</h2>
    
    <!-- 飙升产品列表 -->
    <div class="card mb-4">
        <div class="card-header">
            <h4>飙升产品列表</h4>
        </div>
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th>产品ID</th>
                            <th>标题</th>
                            <th>飙升指数</th>
                            <th>排名变化</th>
                            <th>销量变化</th>
                            <th>评论变化</th>
                        </tr>
                    </thead>
                    <tbody>
                        {% for product in surging_products %}
                        <tr>
                            <td>{{ product.productid }}</td>
                            <td>{{ product.title[:30] }}...</td>
                            <td>{{ "%.2f"|format(product.surge_index) }}</td>
                            <td>{{ "%.2f"|format(product.rank_change) }}</td>
                            <td>{{ "%.2f"|format(product.sales_change) }}</td>
                            <td>{{ "%.2f"|format(product.review_change) }}</td>
                        </tr>
                        {% endfor %}
                    </tbody>
                </table>
            </div>
        </div>
    </div>

    <!-- 市场分析 -->
    <div class="card mb-4">
        <div class="card-header">
            <h4>市场分析</h4>
        </div>
        <div class="card-body">
            <div class="row">
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">市场需求</h5>
                            <p class="card-text">{{ "%.2f"|format(market_demand) }}</p>
                            <small class="text-muted">基于所有产品的平均需求指数</small>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">竞争程度</h5>
                            <p class="card-text">{{ "%.2f"|format(competition_level) }}</p>
                            <small class="text-muted">基于所有产品的平均竞争指数</small>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="card">
                        <div class="card-body">
                            <h5 class="card-title">盈利能力</h5>
                            <p class="card-text">{{ "%.2f"|format(profitability) }}</p>
                            <small class="text-muted">基于所有产品的平均盈利指数</small>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 详细分析 -->
    <div class="card">
        <div class="card-header">
            <h4>详细分析</h4>
        </div>
        <div class="card-body">
            {% for result in results %}
            <div class="card mb-3">
                <div class="card-header">
                    <h5>产品ID: {{ result.productid }}</h5>
                </div>
                <div class="card-body">
                    <div class="row">
                        <div class="col-md-6">
                            <p><strong>标题:</strong> {{ result.title }}</p>
                            <p><strong>销量:</strong> {{ result.sales_info }}</p>
                            <p><strong>评分:</strong> {{ result.rating }}</p>
                            <p><strong>评论数:</strong> {{ result.reviews_count }}</p>
                        </div>
                        <div class="col-md-6">
                            <p><strong>优化后的标题:</strong> {{ result.optimized_title }}</p>
                            <p><strong>优化后的五点描述:</strong></p>
                            <ul>
                                {% for bullet in result.optimized_bullets|from_json %}
                                <li>{{ bullet }}</li>
                                {% endfor %}
                            </ul>
                            <p><strong>关键词建议:</strong></p>
                            <ul>
                                {% for keyword in result.keyword_suggestions|from_json %}
                                <li>{{ keyword }}</li>
                                {% endfor %}
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
            {% endfor %}
        </div>
    </div>
</div>
{% endblock %} 